package com.src.myapplication.ui.view.fragmentzhibo;

import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.src.myapplication.R;
import com.src.myapplication.base.BaseFragmentSwp;
import com.src.myapplication.bean.XinRenben;
import com.src.myapplication.config.UrlConfig;
import com.src.myapplication.utils.UIManager;
import com.src.myapplication.widget.CommonAdapter;
import com.src.myapplication.widget.PlayActivity;
import com.src.myapplication.widget.base.ViewHolder;
import com.youth.banner.Banner;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/10/17.
 */
public class XinRen extends BaseFragmentSwp {


    private RecyclerView mRcv;
    private Banner mBanner;

    @Override
    protected void initData(View view) {
        mRcv = (RecyclerView) view.findViewById(R.id.rcv);
        mBanner = (Banner) view.findViewById(R.id.banner);
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_xinren;
    }

    @Override
    public int getid() {
        return R.id.sw;
    }

    @Override
    public String geturl() {
        return UrlConfig.ZhiBo.ZHIBO_XINREN;
    }

    @Override
    public Class<? extends Object> getben() {
        return XinRenben.class;
    }

    @Override
    public void addList(final String string) {
        if (string != null) {
            Gson gson = new Gson();
            List<XinRenben> list = new ArrayList<>();
            Type type = new TypeToken<ArrayList<XinRenben>>() {
            }.getType();
            list = gson.fromJson(string, type);
            CommonAdapter<XinRenben> adapter1 = new CommonAdapter<XinRenben>(getContext(), R.layout.fragment_xinren_list, list) {
                @Override
                protected void convert(ViewHolder holder, XinRenben xinRenben, int position) {
                    int users = xinRenben.getUsers();//观看人数
                    int uid = xinRenben.getUid();
                    final String id = String.valueOf(uid);
                    final String nickname = xinRenben.getUser().getNickname();//名称
                    String mingcheng = xinRenben.getCover();//neir
                    TextView name = holder.getView(R.id.name);
                    TextView bott = holder.getView(R.id.bott);
                    ImageView neirong = holder.getView(R.id.neirong);
                    name.setText(String.valueOf(users));
                    bott.setText(nickname);
                    Glide.with(getContext()).load(mingcheng).into(neirong);
                    String rtmp = xinRenben.getRtmp();
                   final String[] data=new String[]{id,nickname,mingcheng,rtmp};
                    neirong.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            UIManager.startActivity(getContext(), PlayActivity.class, data);
                        }
                    });

                }
            };
//            BaseRecyclerAdapter adapter = new BaseRecyclerAdapter<>(adapter1);
//            View inflate = LayoutInflater.from(getContext()).inflate(R.layout.header, null);
//            mBanner = (Banner) inflate.findViewById(R.id.banner);
//            mBanner.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,200));
//            adapter.addHeader(mBanner);
//            String[] images =new String[]{UrlConfig.ZhiBo.ZHIBO_XINREN_TITLE};
//            mBanner.setImages(Arrays.asList(images)).setDelayTime(5000).setImageLoader(new GlideImageLoader()).start();
            StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);

            mRcv.setLayoutManager(manager);
            mRcv.setAdapter(adapter1);

        }
    }


    @Override
    public void showLoadFailMsg() {

    }

}